package com.example.planetexploder.module.menu;

import android.content.Context;
import android.util.Log;

import com.example.planetexploder.bean.otherdata.MenuItem;
import com.example.planetexploder.bean.otherdata.Classification;
import com.example.planetexploder.constants.LogConst;
import com.example.planetexploder.model.preference.SharedPreference;

import java.util.ArrayList;

public class Presenter_Menu {

    private SharedPreference sp;

    public Presenter_Menu(Context context) {
        sp = new SharedPreference(context);
    }

    public ArrayList<MenuItem> create_Menu() {
        Log.d(LogConst.PTAG, "create_Menu()");
        ArrayList<MenuItem> listMenu = new ArrayList<MenuItem>();
        ArrayList<Classification> cls = sp.classifications.get_allClassification();
        for (int i = 0; i < cls.size(); i++) {
            listMenu.add(new MenuItem(cls.get(i).tagName,cls.get(i).tag));
        }
        return listMenu;
    }

    /**
     * 创建自定义分类
     */
    public void create_Tag(String tagName) {
        Log.d(LogConst.PTAG, "create_Tag()");
        sp.classifications.save_Classification(tagName);
    }

    /**
     * 删除自定义分类
     */
    public void delete_Tag(int tagId) {
        Log.d(LogConst.PTAG, "delete_Tag()");
        sp.classifications.delete_Classification(tagId);
    }
}
